
***************************************************
* Figure B.2
***************************************************

use "$workdata/baseline", clear /* see $data_do/baseline.do */

capture drop time_w
g time_w=0
local w_count=0
forvalues year=2000/2006{
sum week if year==`year'
replace time_w=`w_count'+week if year==`year'
local w_count=`w_count'+r(max)
}

xtset pnr time_w

capture drop in_sampl into_sample outof_sample
g in_sample=1
g into_sample=in_sample==1 & l.in_sample!=1
g outof_sample=in_sample==1 & f.in_sample!=1

g b_year=year(foed_dagl)
g b_month=month(foed_dagl)


preserve

g age_w=floor( (age-floor(age))*52)*(1/52) + floor(age)

local age="age_w"

collapse (max) in_sample  if age_q>=24 & age_q<26 , by(pnr `age' year)
collapse (sum) in_sample  , by(`age' year)
tab age

g age_q0=`age'-25

forvalues year=2000/2006 {
sum in_sample if year==`year'
replace in_sample=in_sample/r(sum) if year==`year'
}

twoway ///
(scatter in_sample age_q0 if year==2000, msymbol(oh) mcolor(red)) ///
(scatter in_sample age_q0 if year==2001, msymbol(oh) mcolor(blue)) ///
(scatter in_sample age_q0 if year==2002) ///
(scatter in_sample age_q0 if year==2003) ///
(scatter in_sample age_q0 if year==2004) ///
(scatter in_sample age_q0 if year==2005) ///
(scatter in_sample age_q0 if year==2006) 

lpoly in_sample age_q0 if age_q0<0 , bw(0.05) deg(2) n(100) gen(x0 s0) ci se(se0)
lpoly in_sample age_q0 if age_q0>=0, bw(0.05) deg(2) n(100) gen(x1 s1) ci se(se1)
forvalues v=0/1 {
	g ul`v'=s`v'+1.96*se`v'
	g ll`v'=s`v'-1.96*se`v'
}

twoway ///
(line ul0 ll0 s0 x0, lcolor(gs6 gs6 gs4) lpattern(shortdash shortdash solid) lwidth(medium medium medthin)) ///
(line ul1 ll1 s1 x1, lcolor(gs6 gs6 gs4) lpattern(shortdash shortdash solid) lwidth(medium medium medthin)) ///
, legend(order( 3 "Local polynomial smooth" 1 "CI")) xtitle("Years from cutoff", height(5)) ytitle("Density", height(5)) ///
scheme(s1mono)  xline(-0.0096154) name(figB2, replace)

graph save figB2  $figures/figB2, replace
graph export $figures/figB2.pdf, name(figB2) replace
graph export $figures/figB2.png, name(figB2) replace

restore

***************************************************
* end: Figure B.2
***************************************************

